import { ref } from "vue";
export const timestamp = (timestamp) => {
  var date = new Date(0); // 注意：JavaScript使用毫秒，因此要乘以1000
  date.setUTCSeconds(timestamp);
  // 获取日期的各个部分
  var year = date.getFullYear();
  var month = date.getMonth() + 1; // 月份从0开始，因此要加1
  var day = date.getDate();

  // 格式化输出日期
  var formattedDate = year + "-" + addZero(month) + "-" + addZero(day);

  return formattedDate;
};
function addZero(num) {
  return num < 10 ? "0" + num : num;
}

export const timestamp1 = (timestamp) => {
  var date = new Date(0); // 注意：JavaScript使用毫秒，因此要乘以1000
  date.setUTCSeconds(timestamp);
  // 获取日期的各个部分
  var year = date.getFullYear();
  var month = date.getMonth() + 1; // 月份从0开始，因此要加1
  var day = date.getDate();
  var hours = date.getHours(); // 小时
  var minutes = date.getMinutes(); // 分钟
  var seconds = date.getSeconds(); // 秒数
  // 格式化输出日期
  var formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;

  return formattedDate;
};
// function addZero(num) {
//   return num < 10 ? "0" + num : num;
// }

import doms from "./json/dom";
export const diqu = (data) => {
  const foundElement = doms.find((element) => element.adcode == data);

  if (foundElement) {
    return foundElement.label;
  }

  // 如果没有找到匹配项，可以返回一个默认值或者 null，具体根据需求而定
  return "全国";
};

// 金额
export const money = (event) => {
  event = event * 1
  var a = null;
  if (event > 10000 && 100000000 > event) {
    // console.log(event, "555");
    a = event / 10000;
    a = a.toFixed(3) + "万元";
  } else if (event > 100000000) {
    a = event / 1000000000;
    a = a.toFixed(3) + "亿元";
    // a=event/100000000+'亿元'
  } else if (event < 10000) {
    a = event;
    a = a.toFixed(3) + "元";
  }
  return a;
  // if (mn < 10000) {
  //   // 如果小于一万，返回原值
  //   return mn + "元";
  // } else if (mn < 100000000) {
  //   // 如果大于等于一万，小于一亿，除以一万并保留两位小数
  //   return (mn / 10000).toFixed(3) + "万元";
  // } else {
  //   // 如果大于等于一亿，除以一亿并保留两位小数
  //   return (mn / 100000000).toFixed(3) + "亿";
  // }
};
// 金额
export const money1 = (event) => {
  event = event * 1
  var a = null;
  if (event > 10000 && 100000000 > event) {
    // console.log(event, "555");
    a = event / 10000;
    a = a.toFixed(3) + "万次";
  } else if (event > 100000000) {
    a = event / 1000000000;
    a = a.toFixed(3) + "亿次";
    // a=event/100000000+'亿元'
  } else if (event < 10000) {
    a = event;
    a = a.toFixed(3) + "次";
  }
  return a;
  // if (mn < 10000) {
  //   // 如果小于一万，返回原值
  //   return mn + "元";
  // } else if (mn < 100000000) {
  //   // 如果大于等于一万，小于一亿，除以一万并保留两位小数
  //   return (mn / 10000).toFixed(3) + "万元";
  // } else {
  //   // 如果大于等于一亿，除以一亿并保留两位小数
  //   return (mn / 100000000).toFixed(3) + "亿";
  // }
};

export const moneydw = (mn) => {
  if (mn < 10000) {
    // 如果小于一万，返回原值
    return "元";
  } else if (mn < 100000000) {
    // 如果大于等于一万，小于一亿，除以一万并保留两位小数
    return "万元";
  } else {
    // 如果大于等于一亿，除以一亿并保留两位小数
    return "亿";
  }
};
export const moneys = (mn) => {
  if (mn == "NaN") return "0";
  if (mn < 10000) {
    // 如果小于一万，返回原值
    return mn;
  } else if (mn < 100000000) {
    // 如果大于等于一万，小于一亿，除以一万并保留两位小数
    return (mn / 10000).toFixed(3);
  } else {
    // 如果大于等于一亿，除以一亿并保留两位小数
    return (mn / 100000000).toFixed(3);
  }
};

// 积分平台
export const terrace = (platform_status) => {
  if ((platform_status = "1")) {
    return "PC端";
  } else if ((platform_status = "2")) {
    return "小程序";
  } else if ((platform_status = "3")) {
    return "H5";
  }
};

// 积分明细内容
export const pointsrrace = (type_status) => {
  if ((type_status = "1")) {
    return "签到";
  } else if ((type_status = "2")) {
    return "邀请好友注册";
  } else if ((type_status = "3")) {
    return "首次绑定邮箱";
  } else if ((type_status = "4")) {
    return "填写公司信息";
  } else if ((type_status = "5")) {
    return "新用户注册";
  } else if ((type_status = "6")) {
    return "查看标讯";
  } else if ((type_status = "7")) {
    return "查看联系人";
  } else if ((type_status = "8")) {
    return "查看公司";
  }
};

// 隐藏姓名
export const showFirstName = (name) => {
  let newStr;
  if (name.length === 2) {
    newStr = name.substr(0, 1) + "*";
  } else if (name.length > 2) {
    let char = "";
    for (let i = 0, len = name.length - 1; i < len; i++) {
      char += "*";
    }
    newStr = name.substr(0, 1) + char;
  } else {
    newStr = name;
  }
  return newStr;
};
//项目处理进度
export const type_status = (type_status) => {
  // console.log(type_status);
  if (type_status == "1") {
    return "联系中";
  } else if (type_status == "2") {
    return "已投标";
  } else if (type_status == "3") {
    return "已合作";
  } else if (type_status == "4") {
    return "放弃";
  } else if (type_status == "5") {
    return "不相关";
  } else if (type_status == "6") {
    return "已中标";
  } else if (type_status == "7") {
    return "未中标";
  }
};

// 加解密
import CryptoJS from "crypto-js";
const key = CryptoJS.enc.Utf8.parse("ysh425ptjhcpo781"); //十六位十六进制数作为密钥偏移量
const iv = CryptoJS.enc.Utf8.parse("53c5a64c6be84e97"); //十六位十六进制数作为密钥偏移量
const jiam = ref();
//加密
export const encrypt = (text) => {
  return CryptoJS.AES.encrypt(text, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  }).toString();
};
// jiam.value = encrypt(`{"id":2,"name":"132139432"}`);
// console.log(jiam.value);
// const jiem = ref('');
//解密
export const decrypt = (text) => {
  var result = CryptoJS.AES.decrypt(text, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  });
  return result.toString(CryptoJS.enc.Utf8);
};
// jiem.value = decrypt(
//   "NZHq+V7j9hdrMgL1CRk9Dp6TeGlpRT1HK64fp0kciJh95fvGc4vszO9YNQtmOCoEM/9QJGUwJ/CI3BmCfGoqkCycOT1unIlkN27ri40bFgM0FbuUXhYVvBV2NncUHMu6+KQ7b13/qlzor4xE2HRCbS79YRCmIDg1Q32AyHjW1056LdcfssiC8HBGiKOWlI+D8NRqScv/Saaf5WeqLPR90ww7ii4+T97yQ1mfg2jTqS0="
// );
// console.log(jiem.value);
